﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using DomusDotNet.SBS.ObjectModel;

namespace DomusDotNet.SBS.UI.ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {

            ////Set DB strategy.
            ////Drop Database if model changes.
            Database.SetInitializer<Db>(new DropCreateDatabaseIfModelChanges<Db>());

            using (Db db = new Db())
            {
                try
                {
                    var books = from b in db.Books select b;

                    Console.WriteLine("Books count:" + books.Count().ToString());

                    Book book = new Book();

                    book.ID = 1;
                    book.ISBN = "ISBN-100";
                    book.Title = "Programming C# 4";
                    book.Version = 1;
                    book.Volume = 1;
                    book.Available = true;
                    book.Editor = new Editor()
                    {
                        ID = 1,
                        Nominative = "McGraw Hill",
                        Address =
                        new Address()
                        {
                            City = "Ney York",
                            StreetAddress = "Third Street",
                            ZipCode = "00123"
                        }
                    };

                    db.Books.Add(book);
                    int rowsAffected = db.SaveChanges();

                    Console.WriteLine("Rows Affected = {0} ", rowsAffected);
                    Console.ReadLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }
}
